﻿using Microsoft.Extensions.DependencyInjection;

namespace Magic.System;

public class LogEventSubscriber : IEventSubscriber
{
    public LogEventSubscriber(IServiceProvider services)
    {
        Services = services;
    }

    public IServiceProvider Services { get; }

    [EventSubscribe(EventConst.LoginCallBack)]
    public async Task LoginCallBack(EventHandlerExecutingContext context)
    {
        var payload = (EventLoginCallBackDto)context.Source.Payload;
        await SugarContext.Instance.Updateable<SysUser>()
            .SetColumns(m => new SysUser { Lastlogintime = payload.Lastlogintime, Lastloginip = payload.Lastloginip })
            .Where(m => m.Id == payload.UserId).ExecuteCommandAsync();
    }
}
